package com.output;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutputStreamDemo {
    public static void main(String[] args) {
        // jdk7之前
        /*
        FileOutputStream fos=null;
        try {
            fos=new FileOutputStream("D:\\A.txt");
            fos.write("abc".getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
         */

        // jdk7之后
        try(FileOutputStream fos=new FileOutputStream("D:\\A.txt")){
            fos.write("dawdw".getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
